﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Xml;

namespace SpringBeansEditor.Commands
{
    public class AddPropertyCommand: IXmlCommand
    {
        public bool IsAllowedInNode(XmlNode curr_xml_node)
        {
            return (curr_xml_node.Name.ToLowerInvariant() == "object") ||
                (curr_xml_node.Name.ToLowerInvariant() == "property");
        }

        public string GetLabel()
        {
            return "Add Property";
        }

        public void Execute(XmlDocument xml_data, XmlNode curr_xml_node)
        {
            string node_name = curr_xml_node.Name.ToLowerInvariant();
            XmlElement new_node = xml_data.CreateElement("property", "http://www.springframework.net");
            new_node.SetAttribute("name", "");
            if (curr_xml_node.Name.ToLowerInvariant() == "object")
            {
                curr_xml_node.AppendChild(new_node);
            }
            else
            {
                curr_xml_node.ParentNode.AppendChild(new_node);
            }
        }
    }
}
